﻿using MaterialDesignExtensions.Model;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AJWPFAdmin.Core.Components.AJTable.ViewModels
{
    /// <summary>
    /// 表单项目的选项条目
    /// </summary>
    public class AJTableFormSchemaItemOptions : BindableBase
    {
        public string Label { get; set; }
        public object Value { get; set; }
        public object OtherData { get; set; }

        private bool _checked;
        public bool Checked
        {
            get { return _checked; }
            set { SetProperty(ref _checked, value); }
        }
    }

    public class AJTableFormSchemaItemOptionAutoCompleteSource : AutocompleteSource<AJTableFormSchemaItemOptions>
    {
        private IList<AJTableFormSchemaItemOptions> _sources;

        public AJTableFormSchemaItemOptionAutoCompleteSource(IList<AJTableFormSchemaItemOptions> sources)
        {
            _sources = sources;
        }

        public override IEnumerable<AJTableFormSchemaItemOptions> Search(string searchTerm)
        {
            searchTerm = searchTerm ?? string.Empty;
            searchTerm = searchTerm.ToLower();

            return _sources.Where(p => p.Label.ToLower().Contains(searchTerm));
        }
    }
}
